package mark.tom.gear.base.app

import android.app.Activity
import android.app.Application
import android.os.Bundle
import mark.tom.gear.base.manager.ActivityManager
import mark.tom.gear.base.utils.LogUtil

/**
 * @Description: Application生命周期回调
 * @Author: ttmk110@163.com
 * @Package: mark.tom.gear.base.app
 * @Date: 2021/1/14
 * @Copyright: 版权归 Mark 所有
 * <ModifyLog>
 * @ModifyContent:
 * @Author:
 * @Date:
 * </ModifyLog>
 */
class BaseActivityLifecycleCallback : Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        LogUtil.i("Activity %s onActivityCreated", activity.componentName)
        // 在ActivityManager中记录activity信息
        ActivityManager.instance.addActivity(activity)
    }

    override fun onActivityStarted(activity: Activity) {
        LogUtil.i("Activity %s onActivityStarted", activity.componentName)
    }

    override fun onActivityResumed(activity: Activity) {
        LogUtil.i("Activity %s onActivityResumed", activity.componentName)
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
        // Do Nothing
    }

    override fun onActivityPaused(activity: Activity) {
        LogUtil.i("Activity %s onActivityPaused", activity.componentName)
    }

    override fun onActivityStopped(activity: Activity) {
        LogUtil.i("Activity %s onActivityStopped", activity.componentName)
    }

    override fun onActivityDestroyed(activity: Activity) {
        LogUtil.i("Activity %s onActivityDestroyed", activity.componentName)
        // 在ActivityManager中移除Activity信息
        ActivityManager.instance.removeActivity(activity)
    }

}